<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 找到数组的中间值，一一比较，左右空数组，大小放置，递归
        function quick(arr) {
            // 小于等于1
            if (arr.length <= 1) {
                return arr;
            }
            // else {
            var contentIndex = parseInt(arr.length / 2);    // 取数组中间值的下标
            var contentValue = arr.splice(contentIndex, 1)[0];   // 把这个中间值删除，且记录下来
            var leftArr = [];
            var rightArr = [];
            for (var n = 0; n < arr.length; n++) {
                if (arr[n] < contentValue) {
                    leftArr.push(arr[n]);
                }
                else {
                    rightArr.push(arr[n]);
                }
            }
            return quick(leftArr).concat(contentValue, quick(rightArr));
            // }
        }
        console.log(quick([9, 5, 6, 4, 3, 7]));
    </script>
</body>

</html>